package sanrenxing.updatePwd.dao.impl;

import sanrenxing.updatePwd.dao.PwdUpdateDao;
import sanrenxing.utils.JdbcUtils;

import java.sql.*;

/**
 * @author Administrator
 * @date 2020/10/14 14:36
 * 编辑者：邓志强
 * 功能：
 */
public class PwdUpdateDaoImpl implements PwdUpdateDao {
    /**
     * 修改教师密码
     *
     * @param userName
     * @param newTeacherPwd
     * @return
     */
    @Override
    public boolean TeacherPwdUpdate(String newTeacherPwd, String userName,String teacherPwd) {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        int rows=0;
        try {
            conn= JdbcUtils.getConnection();
            String sql="UPDATE teacher SET teacherPwd=? WHERE teacherNum=? AND teacherPwd=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1,newTeacherPwd);
            pstmt.setString(2,userName);
            pstmt.setString(3,teacherPwd);
            rows=pstmt.executeUpdate();
            if (rows!=0){
                return true;
            }
        } catch (SQLException e) {
            new RuntimeException(e.getMessage(),e);
        }
        return false;
    }

    /**
     * 修改学员密码
     *
     * @param newStuPwd
     * @param stuId
     * @param stuPwd
     * @return
     */
    @Override
    public boolean StudentPwdUpdate(String newStuPwd, String stuId, String stuPwd) {
        Connection conn=null;
        PreparedStatement pstmt=null;
        ResultSet rs=null;
        int rows=0;
        try {
            conn= JdbcUtils.getConnection();
            String sql="UPDATE student SET stuPwd=? WHERE stuId=? AND stuPwd=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setString(1,newStuPwd);
            pstmt.setString(2,stuId);
            pstmt.setString(3,stuPwd);
            rows=pstmt.executeUpdate();
            if (rows!=0){
                return true;
            }
        } catch (SQLException e) {
            new RuntimeException(e.getMessage(),e);
        }
        return false;
    }
}
